#include "player.h"
#include"stock.h"
Player::Player()
  {

   set_speed(BOARD_SPEED);
   player = new QRect(0,800,BOARD_LENGTH,BOARD_WIDTH);

  }


Player::~Player()
{
    delete player;
}


void Player::set_speed(double s = BOARD_SPEED)
{
    speed = s;
}


int Player::getspeed()
{
    return speed;
};


//实现向右移动，与右键信号响应
void Player::move_right()
{
    if(player->x()<650)
      player->setX(player->x()+15*getspeed());

    else if(player->x()>650)
      player->setX(650);

};


//实现向左移动，与左键信号响应
void Player::move_left()
{
    if(player->x()>0)
       player->setX(player->x()-15*getspeed());

    else if(player->x()<0)
        player->setX(0);

}

QRect Player::getplayer()
{
    return *player;
}


int Player::getx()
{
    return player->x();
}


int Player::gety()
{
    return player->y();
}


void Player::inite_board()
{
    set_speed(BOARD_SPEED);
    player->setX(0);
    player->setY(800);
}
